﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.components.secretary.states {
    import flash.events.*;
    import flash.utils.*;
    import net.wooga.pets.utils.timeline.*;
    import net.wooga.pets.views.components.secretary.*;

    public class ReceptionSecretaryIdleState extends ReceptionSecretaryBaseState implements IReceptionSecretaryState {

        private var timer:Timer;

        private static const DEFAULT_LABEL:String = "idle";
        private static const MINUTE_IN_MILLISECONDS:int = 60000;

        public function ReceptionSecretaryIdleState(_arg1:ReceptionSecretaryViewStateManager, _arg2:SequenceBasedStatesTimeline){
            super(_arg1, _arg2);
            this.timer = new Timer(MINUTE_IN_MILLISECONDS, 0);
        }
        override protected function onTimelineAnimationFinished(_arg1:String):void{
            this.initiate();
            this.doIdle();
        }
        override protected function getStateLabel():String{
            return (DEFAULT_LABEL);
        }
        public function stop():void{
            this.clearTimer();
            this.interrupt();
        }
        public function initiate():void{
            this.gotoAndStop(DEFAULT_LABEL);
        }
        public function doIdle():void{
            if (this.timer.running){
                return;
            };
            this.timer.reset();
            this.timer.start();
            this.timer.addEventListener(TimerEvent.TIMER, this.onTimerComplete);
        }
        private function onTimerComplete(_arg1:TimerEvent):void{
            this.clearTimer();
            this.playFromLabel(this.getStateLabel());
        }
        private function clearTimer():void{
            if (this.timer.running){
                this.timer.removeEventListener(TimerEvent.TIMER, this.onTimerComplete);
            };
            this.timer.reset();
        }
        public function doListening():void{
            super.interrupt();
            this.clearTimer();
            this.context.currentState = this.context.getStateByLookupKey(ReceptionSecretaryViewStateManager.LISTENING_STATE);
            this.context.doListening();
        }
        override public function destroy():void{
            this.clearTimer();
            this.timer = null;
            super.destroy();
        }

    }
}//package net.wooga.pets.views.components.secretary.states 
